﻿using Caliburn.Micro;
using MusicExplorer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MusicExplorer.ViewModels.Wrappers
{
    public sealed class CategoryWrapper : PropertyChangedBase
    {
        private readonly HomePageViewModel m_parent;
        private readonly Category m_category;
        private BindableCollection<QueryGroupTileViewModel> m_groups;

        public CategoryWrapper(HomePageViewModel parent, Category category)
        {
            m_category = category;
            m_parent = parent;
            m_groups = new BindableCollection<QueryGroupTileViewModel>();
        }

        public HomePageViewModel Parent { get { return m_parent; } }

        public string Name
        {
            get { return m_category.Name; }
            set
            {
                if (m_category.Name != value)
                {
                    m_category.Name = value;
                    NotifyOfPropertyChange(() => Name);
                    Parent.SaveNeeded = true;
                }
            }
        }

        public Category Category { get { return m_category; } }

        public BindableCollection<QueryGroupTileViewModel> Groups { get { return m_groups; } }

        private QueryGroupTileViewModel m_selectedGroup;
        public QueryGroupTileViewModel SelectedGroup { get { return m_selectedGroup; } }

        public void RefreshSelectedGroup()
        {
            m_selectedGroup = m_groups.FirstOrDefault(g => g.IsSelected);
            NotifyOfPropertyChange(() => SelectedGroup);
            Parent.RefreshSelectedGroup();
        }
    }
}
